 package handling.channel.handler;

 import client.MapleCharacter;
 import client.MapleClient;
 import client.inventory.Item;
 import client.inventory.MapleInventoryType;
 import client.inventory.MaplePotionPot;
 import server.MapleInventoryManipulator;
 import server.MapleItemInformationProvider;
 import server.MapleStatEffect;
 import tools.MaplePacketCreator;
 import tools.data.input.LittleEndianAccessor;
 import tools.packet.InventoryPacket;











 public class PotionPotHandler
 {
   public static void PotionPotUse(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/*  28 */     if (chr == null || chr.getMap() == null || chr.getPotionPot() == null || !chr.isAlive()) {
/*  29 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/*  32 */     long time = System.currentTimeMillis();
/*  33 */     if (chr.getNextConsume() > time) {
/*  34 */       c.announce(InventoryPacket.showPotionPotMsg(0, 8));
/*  35 */       c.announce(MaplePacketCreator.enableActions());

       return;
     }
/*  39 */     slea.skip(4);
/*  40 */     short slot = slea.readShort();
/*  41 */     int itemId = slea.readInt();
/*  42 */     Item item = chr.getInventory(MapleInventoryType.CASH).getItem(slot);
/*  43 */     if (item == null || item.getItemId() != itemId || itemId / 10000 != 582) {
/*  44 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/*  47 */     MaplePotionPot potionPot = chr.getPotionPot();
/*  48 */     int potHp = potionPot.getHp();
/*  49 */     int potMp = potionPot.getMp();
/*  50 */     if (potHp == 0 && potMp == 0) {
/*  51 */       c.announce(InventoryPacket.updataPotionPot(potionPot));
/*  52 */       c.announce(InventoryPacket.showPotionPotMsg(0, 6));
       return;
     }
/*  55 */     boolean usePot = false;
/*  56 */     int healHp = chr.getStat().getHealHp();
/*  57 */     int healMp = chr.getStat().getHealMp(chr.getJob());
/*  58 */     int usePotHp = (potHp >= healHp) ? healHp : potHp;
/*  59 */     int usePotMp = (potMp >= healMp) ? healMp : potMp;
/*  60 */     if (usePotHp > 0) {
/*  61 */       chr.addHP(usePotHp);
/*  62 */       potionPot.setHp(potHp - usePotHp);
/*  63 */       usePot = true;
     }
/*  65 */     if (usePotMp > 0) {
/*  66 */       chr.addMP(usePotMp);
/*  67 */       potionPot.setMp(potMp - usePotMp);
/*  68 */       usePot = true;
     }
/*  70 */     if (usePot && chr.getMap().getConsumeItemCoolTime() > 0) {
/*  71 */       chr.setNextConsume(time + (chr.getMap().getConsumeItemCoolTime() * 1000));
     }
/*  73 */     c.announce(InventoryPacket.updataPotionPot(potionPot));
/*  74 */     c.announce(InventoryPacket.showPotionPotMsg(usePot ? 1 : 0, 0));
   }




   public static void PotionPotAdd(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/*  81 */     if (chr == null || chr.getMap() == null || chr.getPotionPot() == null || !chr.isAlive()) {
/*  82 */       c.announce(MaplePacketCreator.enableActions());

       return;
     }

/*  87 */     slea.skip(4);
/*  88 */     short slot = slea.readShort();
/*  89 */     int itemId = slea.readInt();
/*  90 */     short quantity = (short)slea.readInt();
/*  91 */     Item toUse = chr.getInventory(MapleInventoryType.USE).getItem(slot);
/*  92 */     if (toUse == null || toUse.getQuantity() < 1 || toUse.getItemId() != itemId || toUse.getQuantity() < quantity) {
/*  93 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/*  96 */     MaplePotionPot potionPot = chr.getPotionPot();
/*  97 */     MapleStatEffect itemEffect = MapleItemInformationProvider.getInstance().getItemEffect(itemId);
/*  98 */     if (itemEffect != null) {

/* 100 */       int addHp = itemEffect.getHp();
/* 101 */       if (itemEffect.getHpR() > 0.0D) {
/* 102 */         int hp = chr.getStat().getCurrentMaxHp();
/* 103 */         if (hp > 100000) {
/* 104 */           hp = (int)(itemEffect.getHpR() * 100000.0D) - 1;
         } else {
/* 106 */           hp = (int)(itemEffect.getHpR() * hp);
         }
/* 108 */         addHp += hp;
       }
/* 110 */       addHp = (int)(addHp * 1.2D);

/* 112 */       int addMp = itemEffect.getMp();
/* 113 */       if (itemEffect.getMpR() > 0.0D) {
/* 114 */         int mp = chr.getStat().getCurrentMaxMp(chr.getJob());
/* 115 */         if (mp > 100000) {
/* 116 */           mp = (int)(itemEffect.getMpR() * 100000.0D) - 1;
         } else {
/* 118 */           mp = (int)(itemEffect.getMpR() * mp);
         }
/* 120 */         addMp += mp;
       }
/* 122 */       addMp = (int)(addMp * 1.2D);
/* 123 */       if (addHp <= 0 && addMp <= 0) {
/* 124 */         c.announce(InventoryPacket.updataPotionPot(potionPot));
/* 125 */         c.announce(InventoryPacket.showPotionPotMsg(0, 0));
         return;
       }
/* 128 */       if (potionPot.isFull(addHp, addMp)) {
/* 129 */         c.announce(InventoryPacket.updataPotionPot(potionPot));
/* 130 */         c.announce(InventoryPacket.showPotionPotMsg(0, 2));

         return;
       }
/* 134 */       boolean isFull = false;
/* 135 */       short useQuantity = 0;
/* 136 */       while (!isFull) {
/* 137 */         potionPot.addHp((addHp > 0) ? addHp : 0);
/* 138 */         potionPot.addMp((addMp > 0) ? addMp : 0);
/* 139 */         useQuantity = (short)(useQuantity + 1);

/* 141 */         isFull = (potionPot.isFull(addHp, addMp) || useQuantity == quantity);
       }
/* 143 */       if (useQuantity > 0) {
/* 144 */         MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, useQuantity, false);
       }
/* 146 */       c.announce(InventoryPacket.updataPotionPot(potionPot));
/* 147 */       c.announce(InventoryPacket.showPotionPotMsg(2));
     }
/* 149 */     c.announce(MaplePacketCreator.enableActions());
   }




   public static void PotionPotMode(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 156 */     if (chr == null || chr.getMap() == null || chr.getPotionPot() == null) {
/* 157 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 160 */     c.announce(MaplePacketCreator.enableActions());
   }




   public static void PotionPotIncr(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 167 */     if (chr == null || chr.getMap() == null || chr.getPotionPot() == null) {
/* 168 */       c.announce(MaplePacketCreator.enableActions());

       return;
     }
/* 172 */     slea.skip(4);
/* 173 */     slea.skip(1);
/* 174 */     int itemId = slea.readInt();
/* 175 */     short slot = slea.readShort();
/* 176 */     Item toUse = chr.getInventory(MapleInventoryType.CASH).getItem(slot);
/* 177 */     if (toUse == null || toUse.getQuantity() < 1 || toUse.getItemId() != itemId || itemId != 5821000) {
/* 178 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 181 */     MaplePotionPot potionPot = chr.getPotionPot();
/* 182 */     boolean useItem = potionPot.addMaxValue();
/* 183 */     if (useItem) {
/* 184 */       MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.CASH, slot, (short)1, false);
     }
/* 186 */     c.announce(InventoryPacket.updataPotionPot(potionPot));
/* 187 */     c.announce(InventoryPacket.showPotionPotMsg(useItem ? 3 : 0, useItem ? 0 : 3));
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\PotionPotHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */